import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class test5_2 {
    public static void main(String[] args) {
        int[] nums = {-2,0,1,1,2};
        Arrays.sort(nums);
        int n = nums.length;
        List<List<Integer>> list = new ArrayList<>();
        for (int i = 0; i < n; ) {

            if(nums[i]>0){
                break;
            }

            int left = i+1;
            int right = n - 1;
            int target = -nums[i];

            while (left < right) {
                int sum = nums[left] + nums[right];
                if (sum > target) {
                    right--;

                } else if (sum < target) {
                    left++;

                } else {
                    List<Integer> newlist = new ArrayList<>();
                    newlist.add(nums[i]);
                    newlist.add(nums[left]);
                    newlist.add(nums[right]);

                    list.add(newlist);
//                    list.add(new ArrayList<Integer>(Arrays.asList(nums[left], nums[right], nums[max])));

                    left++; right--;
                    while (left < right && nums[left - 1] == nums[left]   ) {
                        left++;
                    }

                    while (left < right && nums[right + 1] == nums[right]  ) {
                        right--;
                    }
                }


            }
            i++;
            while (i < n && nums[i - 1] == nums[i]  ) {
                i++;
            }
        }

       for (int i1 = 0; i1 < list.size(); i1++) {

           for (int i2 = 0; i2 < list.get(i1).size(); i2++) {
               System.out.print(list.get(i1).get(i2) + " ");
           }
       }

    }
}
